//
//  DDShopInfoView.m
//  Dingdong
//
//  Created by 程强 on 16/11/17.
//  Copyright © 2016年 程强. All rights reserved.
//

#import "DDShopInfoView.h"

typedef void(^EnterShop)();

@interface DDShopInfoView()
@property (strong, nonatomic) UIImageView *logo;
@property (strong, nonatomic) KKLabel *nameLbl;
@property (strong, nonatomic) EnterShop enterBlock;
@end

@implementation DDShopInfoView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.logo = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        _logo.image = LoadImage(@"");
        _logo.contentMode = UIViewContentModeScaleAspectFill;
        _logo.clipsToBounds = YES;
        [self addSubview:_logo];
        [_logo mas_updateConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(self).offset(10.0);
            make.height.equalTo(self).offset(-20);
            make.width.equalTo(_logo.mas_height).multipliedBy(1.0);
        }];
        
        self.nameLbl = [[KKLabel alloc]initWithBlock:^(KKLabel *lbl) {
            lbl.laText(@"",[UIColor blackColor],[UIFont systemFontOfSize:15.0],NSTextAlignmentLeft);
        }];
        [self addSubview:_nameLbl];
        [_nameLbl mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_logo.mas_right).offset(10);
            make.right.equalTo(self).offset(-20);
            make.top.equalTo(_logo);
            make.height.equalTo(@30);
        }];
        
//        UIButton *enterBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//        [enterBtn setTitle:@"Enter Shop" forState:UIControlStateNormal];
//        enterBtn.backgroundColor = kRedColor;
//        enterBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
//        enterBtn.layer.cornerRadius = 2.0;
//        [enterBtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
//        [self addSubview:enterBtn];
//        [enterBtn mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(_logo.mas_right).offset(10);
//            make.bottom.equalTo(_logo.mas_bottom).offset(-5);
//            make.width.equalTo(@85);
//            make.height.equalTo(@30);
//        }];
    }
    return self;
}
- (void)setShopName:(NSString *)shopName
{
    _shopName = shopName;
    self.nameLbl.text = shopName;
}
- (void)enterClick:(UIButton *)btn
{
    if (self.enterBlock) {
        self.enterBlock();
    }
}
- (void)enterInToShop:(void(^)())block
{
    self.enterBlock = block;
}
- (void)setLogoUrl:(NSString *)logoUrl
{
    _logoUrl = logoUrl;
    [self.logo sd_setImageWithURL:[NSURL URLWithString:logoUrl] placeholderImage:nil];
}
@end
